# PURPOSE: Produce file and output for Mixed-Poisson AR(1) IWY simulations
#
#
# AUTHORS: Stefanos Kechagias, James Livsey
#
# DATE: May 2020
#
# R version 3.6.3
# Set working directory to location where all files should be written
# simulation_function.R should also live here
setwd("~/github/countsFun/Sims/MixedPoissonAR1/IYW")
# Source main simulation function
source('simulation_function.R')
# Fixed parameters for all simulations
nsim <- 200
prob <- 1/4
# Parameter sequences
n_seq <- c(100, 200, 400)
lam1_seq <- 2
lam2_seq <- c(3, 5, 10)
prob_seq <- 1/4
phi_seq <- c(-.75, .75)
# Loop and define parameters for each simulation
for(n_idx in 1:length(n_seq)){
for(lam1_idx in 1:length(lam1_seq)){
for(lam2_idx in 1:length(lam2_seq)){
for(phi_idx in 1:length(phi_seq)){
n <- n_seq[n_idx]
lam1 <- lam1_seq[lam1_idx]
lam2 <- lam2_seq[lam2_idx]
phi <- phi_seq[phi_idx]
PhiSign = ifelse(phi > 0, 'Pos', 'Neg') # SIGN OF ar(1) param
# File name
fileName <- sprintf("MixedPois%s-%sAR1_IYW_N%s_NS%s_Phi%s",
lam1, lam2, n, nsim, PhiSign)
print(fileName)
# Generate an R launch script
contents = paste(
sprintf("# This is an autogenerated script"),
sprintf("n = %d", n),
sprintf("lam1 = %d", lam1),
sprintf("lam2 = %d", lam2),
sprintf("prob = %f", prob),
sprintf("phi = %f", phi),
sprintf("nsim = %d", nsim),
sprintf('df = simulation_mixedPoissonAR1(n, lam1, lam2, phi, prob, nsim)'),
sep = "\n"
)
ff = sprintf("%s.R", fileName)
cat(contents, "\n", file = ff)
# Source file you just created to get object 'df' in Global Environment
source(ff)
saveFileName <- paste0(fileName, ".RData")
save(df, file = saveFileName)
}}}}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.